import http from "../utils/request"
import {PageRequestType, ResponseType, PageResponseType} from "../types/Response";
import {AxiosResponse} from "axios";

const apiPrefix:string = "/address";

export interface AddressType {
    // user_id
    user_id?:string|null|undefined
    // 主键
    id?:string|null|undefined
    // 地址名称
    title?:string|null|undefined
    // 国家
    country?:string|null|undefined
    // 省
    province?:string|null|undefined
    // 市
    city?:string|null|undefined
    // 区
    district?:string|null|undefined
    // 姓名
    name?:string|null|undefined
    // 手机号
    phone?:string|null|undefined
    // 邮箱
    email?:string|null|undefined
    // 详细地址
    address?:string|null|undefined
    // 收件人姓名
    recipients?:string|null|undefined
    others?:string|null|undefined
    newCity?:string|null|undefined
}

export interface AddressPageSearchType extends PageRequestType, AddressType {
}


export async function addAddress(data: AddressType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'post'
    })
}

export async function deleteAddressById(id: string): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'delete'
    })
}

export async function deleteAddressByIds(ids: string[]): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            ids
        },
        url: apiPrefix+'/batch',
        method: 'delete'
    })
}


export async function searchAddressById(id: string): Promise<AxiosResponse<ResponseType<AddressType>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'get'
    })
}

export async function searchAddress(params?: AddressType): Promise<AxiosResponse<ResponseType<AddressType[]>>> {
    return await http.request({
        params: params,
        url: apiPrefix,
        method: 'get'
    })
}

export async function searchAddressByPage(params: AddressPageSearchType): Promise<AxiosResponse<ResponseType<PageResponseType<AddressType>>>> {
    return await http.request({
        params: params,
        url: apiPrefix+'/page',
        method: 'get'
    })
}


export async function updateAddressById(data: AddressType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'put'
    })
}
